import instance from "@/http/index.js";

// 发布消息
export const publishMessage = (data) => {
  const {
    message_title,
    message_category,
    message_publish_department,
    message_publish_name,
    message_receipt_object,
    message_content,
    message_level,
  } = data;
  return instance({
    url: "/msg/publishMessage",
    method: "POST",
    data: {
      message_title,
      message_category,
      message_publish_department,
      message_publish_name,
      message_receipt_object,
      message_content,
      message_level,
    },
  });
};
// 获取公司公告列表
export const companyMessageList = () => {
  return instance({
    url: "/msg/companyMessageList",
    method: "POST",
  });
};
// 获取系统消息列表
export const systemMessageList = () => {
  return instance({
    url: "/msg/systemMessageList",
    method: "POST",
  });
};

// 编辑公告
export const editMessage = (data) => {
  const {
    message_title,
    message_content,
    message_receipt_object,
    message_publish_name,
    message_level,
    message_update_time,
    id,
  } = data;
  return instance({
    url: "/msg/editMessage",
    method: "POST",
    data: {
      message_title,
      message_content,
      message_receipt_object,
      message_publish_name,
      message_level,
      message_update_time,
      id,
    },
  });
};
// 根据发布部门进行获取消息
export const searchMessageByDepartment = (message_publish_department) => {
  // const { message_publish_department } = data;
  return instance({
    url: "/msg/searchMessageByDepartment",
    method: "POST",
    data: {
      message_publish_department,
    },
  });
};
// 根据发布等级进行获取消息
export const searchMessageByLevel = (message_level) => {
  // const { message_level } = data;
  // 单个参数时使用data箭头函数会找不到结果，原因不明
  return instance({
    url: "/msg/searchMessageByLevel",
    method: "POST",
    data: {
      message_level,
    },
  });
};
// 获取公告/系统消息
export const getMessage = (id) => {
  return instance({
    url: "/msg/getMessage",
    method: "POST",
    data: {
      id,
    },
  });
};
// 根据点击次数获取消息
export const updateClick = (data) => {
  const { message_click_number, id } = data;
  return instance({
    url: "/msg/updateClick",
    method: "POST",
    data: {
      message_click_number,
      id,
    },
  });
};
// 初次删除
export const firstDelete = (id) => {
  return instance({
    url: "/msg/firstDelete",
    method: "POST",
    data: {
      id,
    },
  });
};
// 获取回收站的列表
export const recycleList = () => {
  return instance({
    url: "/msg/recycleList",
    method: "POST",
  });
};
// 还原操作
export const recover = (id) => {
  return instance({
    url: "/msg/recover",
    method: "POST",
    data: {
      id,
    },
  });
};
// 删除操作
export const delMessage = (id) => {
  return instance({
    url: "/msg/delMessage",
    method: "POST",
    data: {
      id,
    },
  });
};
// 获取公司公告总数
export const getCompanyMessageLength = () => {
  return instance({
    url: "/msg/getCompanyMessageLength",
    method: "POST",
  });
};
// 获取系统消息公告总数
export const getSystemMessageLength = () => {
  return instance({
    url: "/msg/getSystemMessageLength",
    method: "POST",
  });
};
// 获取系统回收站总数
export const getRecycleMessageLength = () => {
  return instance({
    url: "/msg/getRecycleMessageLength",
    method: "POST",
  });
};
// 监听换页返回数据 公司公告页面
export const returnCompanyListData = (pager) => {
  // const { id } = data;
  return instance({
    url: "/msg/returnCompanyListData",
    method: "POST",
    data: {
      pager,
    },
  });
};
// 监听换页返回数据 系统消息页面
export const returnSystemListData = (pager) => {
  // const { id } = data;
  return instance({
    url: "/msg/returnSystemListData",
    method: "POST",
    data: {
      pager,
    },
  });
};
// 监听换页返回数据 回收站页面
export const returnRecycleListData = (pager) => {
  // const { id } = data;
  return instance({
    url: "/msg/returnRecycleListData",
    method: "POST",
    data: {
      pager,
    },
  });
};
